package tau.pimpmyfreedb.dal;

public class DataFilter {
    public static final int DefaultPageSize = 100;
    
    /**
     * if PageSize == -1 return all matching results
     */
    private int pageSize = -1;
    private int pageIndex = 0;
    private DataType returnType;
    private DataType restrictByItemType;
    private int restrictByItemID;
    private boolean isRestrictByItem;
    private boolean searchExact;
    private String searchString;
    private int dataID;
    private boolean getSpecificID = false;

    public void setReturnType(DataType requestedType) {
        this.returnType = requestedType;
    }

    public DataType getReturnType() {
        return returnType;
    }

    public boolean isRestrictByItem() {
        return isRestrictByItem;
    }

    public int getRestrictByItemID() {
        return restrictByItemID;
    }

    public DataType getRestrictByItemType() {
        return restrictByItemType;
    }

    public void setRestrictByItem(int id, DataType itemType) {
        this.isRestrictByItem = true;
        this.restrictByItemID = id;
        this.restrictByItemType = itemType;
    }

    public void setRestrictByItem(IDataItem item) {
        setRestrictByItem(item.getDataId(), item.getDataType());
    }

    public boolean isTextSearch() {
        return searchString != null && searchString.length() > 0;
    }

    public boolean isSearchExact() {
        return searchExact;
    }

    public String getSearchString() {
        return searchString;
    }

    public void setSearchString(String searchString) {
	setSearchString(searchString, false);
    }

    public void setSearchString(String searchString, boolean exactMatch) {
	this.searchString = searchString;
	this.searchExact = exactMatch;
    }

    public boolean isSpecificID() {
        return getSpecificID;
    }

    public void setSpecificIDToGet(int dataID) {
	this.dataID = dataID;
	this.getSpecificID = true;
    }

    public int getDataID() {
	return dataID;
    }

    public void setUsePaging(boolean usePaging) {
	this.pageSize = usePaging ? DefaultPageSize : -1;
    }

    public boolean isUsePaging() {
	return pageSize > -1;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getPageIndex() {
        return pageIndex;
    }
}
